package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.CarBean;
import com.project.bean.ManBean;
import com.project.mapper.ICarMapper;
import com.project.mapper.IManMapper;
import com.project.service.ICarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CarServiceImpl implements ICarService {
    @Autowired
    private ICarMapper carMapper;
    @Autowired
    private IManMapper manMapper;
    @Override
    public void add(CarBean car) {
        carMapper.insert(car);
    }

    @Override
    public CarBean findById(Integer id) {
        CarBean car = carMapper.selectById(id);
        ManBean man = manMapper.selectById(car.getManId());
        car.setMan(man);

        return car;
    }

    @Override
    public IPage<CarBean> findByItem(Integer pageNO, Integer startPrice, Integer endPrice) {
        return carMapper.findByItem(new Page(pageNO,3),startPrice,endPrice);
    }
}
